import Vue from 'vue'
import Vuex from 'vuex'

//挂载Vuex
Vue.use(Vuex)

//创建VueX对象
const store = new Vuex.Store({
    state: {
        auth: {},
        admin: {},
        tabs: [],
    },
    mutations: {
        auth(state, auth) {
            state.auth = auth;
        },
        admin(state, admin) {
            state.admin = admin;
        },
        // 添加
        addTab(state, router) {
            if (router.name != 'index') {
                for (let k = 0; k < state.tabs.length; k++) {
                    if (router.name == state.tabs[k].name) {
                        return;
                    }
                }
                state.tabs.push({name: router.name, title: router.meta.title,});
            }
        },
        // 删除
        removeTab(state, key) {
            state.tabs.splice(key,1);
        }
    },
})

export default store
